//全局js
//获取手机id
var getUrl = "http://120.27.140.246:8081/sty_v2/";//自己平台
var svgHttp ="http://120.27.140.246:8081/file/" //自己平台的svgIp//svg数据不是只存在一个服务器  
//setIP();
//配置ip的方法
function setIP() {
	
	var address = localStorage.getItem("addr_IP");
	var svtAddress;
	
	try{
		var lastIndex = address.indexOf('/');
		if(address.indexOf('/')== -1){
			 svtAddress = address;
		}else{
			svtAddress = address.substring(0,lastIndex);
		}
	}catch (e) {}
	
//	var LOG_D = localStorage.getItem("logoDu");
	if(address != 'null' && address != null && address != undefined){//address什么都不输入的时候，会默认为输入字符串null，那么字符串null肯定不等于null，那么就不会进入这个函数  所以得考虑字符串null
		getUrl ='http://'+ address + '/';//自己平台
		svgHttp = 'http://'+ svtAddress +'/file/';//自己平台的svgIp//svg数据不是只存在一个服务器
	}
}

var sysId = 'SITCAPP';
var operater='87ad6c822f0047e297e275bb2c7506c8';
//获取当前时间，时间格式为2019-01-19 17:30:22
function currentTime() { 
    var date = new Date();
    var y = date.getFullYear();    
    var m = date.getMonth() + 1;    
    m = m < 10 ? ('0' + m) : m;    
    var d = date.getDate();    
    d = d < 10 ? ('0' + d) : d;    
    var h = date.getHours();  
    h = h < 10 ? ('0' + h) : h;  
    var minute = date.getMinutes();  
    var second = date.getSeconds();  
    minute = minute < 10 ? ('0' + minute) : minute;    
    second = second < 10 ? ('0' + second) : second;   
    return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;    
};  
//获取年月
function currentYM() { 
    var date = new Date();
    var y = date.getFullYear();    
    var m = date.getMonth() + 1;    
    m = m < 10 ? ('0' + m) : m;    
    
    return y + '-' + m ;    
};  
function AMonthAgo() { 
    var Data = new Date();
    var y = Data.getFullYear();
    Data.setMonth(Data.getMonth() - 1);//在获取月份的数值减一   再正常操作  就好
    var m = Data.getMonth() + 1;    
    m = m < 10 ? ('0' + m) : m;    
    var d = Data.getDate();    
    d = d < 10 ? ('0' + d) : d;    
    var h = Data.getHours();  
    h = h < 10 ? ('0' + h) : h;  
    var minute = Data.getMinutes();  
    var second = Data.getSeconds();  
    minute = minute < 10 ? ('0' + minute) : minute;    
    second = second < 10 ? ('0' + second) : second;   
    return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;    
};  
//把数据库得到的时间戳转成此种时间格式2019-01-19 17:30:22
/*function add0(m){return m<10?'0'+m:m }
//时间戳转化成时间格式
	function timeFormat(timestamp){
	  //timestamp是整数，否则要parseInt转换,不会出现少个0的情况
	    var time = new Date(timestamp);
	    var year = time.getFullYear();
	    var month = time.getMonth()+1;
	    var date = time.getDate();
	    var hours = time.getHours();
	    var minutes = time.getMinutes();
	    var seconds = time.getSeconds();
	    return year+'-'+add0(month)+'-'+add0(date)+' '+add0(hours)+':'+add0(minutes)+':'+add0(seconds);
	}*/
	
	//把数据库得到的时间戳转成此种时间格式2019-01-19 17:30:22(方法二)
function dateFormatFs(time){
		if (time != true && time != null && time != "" && !isNaN(time)) {
			var date = new Date(time);
		    var year = date.getFullYear(),
		        month = (date.getMonth() + 1) > 9 ?(date.getMonth() + 1):"0"+(date.getMonth() + 1), //月份是从0开始的
		        day = date.getDate() > 9 ?date.getDate():"0"+date.getDate(),
		        hour = date.getHours() > 9 ?date.getHours():"0"+date.getHours(),
		        min = date.getMinutes() > 9 ?date.getMinutes():"0"+date.getMinutes(),
		        sec = date.getSeconds() > 9 ?date.getSeconds():"0"+date.getSeconds();
		    var newTime = year + '-' +
		                month + '-' +
		                day + ' ' +
		                hour + ':' +
		                min + ':' +
		                sec;
		    return newTime;
		}
	    return time;
	}
	

//存储到缓存
/*localStorage.setItem('stationId', this.getAttribute("stationId"));//把常用的数据存到缓存中
localStorage.setItem('stationName', this.getAttribute("name"));*/
//元与万元的换算：

//调用方法：unitConver(value,type)
//vaue：换算的值，type：0：输出字符串，1：输出json数据

var unitConversion = ["个", "十", "百", "千", "万", "十万", "百万", "千万", "亿", "十亿", "百亿", "千亿", "兆", "十兆", "百兆", "千兆", "京"],
unitConvers = [100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17];
function unitConver(e, t) {
    if (null == e ) return ["--", ""];
    if ( 0 == e) return [e, ""];
    var i = null;
    if ((e = Number(e)) >= 1e3) {
        var r = parseInt(e),
        n = r.toString(),
        o = n.length;
        if (void 0 == t) i = [n = e.toPrecision(o - 1).toString().match(/^\d.\d{2}/)[0], unitConversion[o - 1]];
        else switch (o) {
        case 4:
            i = [(r / unitConvers[1]).toFixed(2), "千"];
            break;
        case 5:
        case 6:
        case 7:
            i = [(r / unitConvers[2]).toFixed(2), "万"];
            break;
        case 8:
            i = [(r / unitConvers[5]).toFixed(2), "千万"];
            break;
        case 9:
        case 10:
        case 11:
            i = [(r / unitConvers[6]).toFixed(2), "亿"];
            break;
        case 12:
             i = [(r / unitConvers[9]).toFixed(2), "千亿"];
            break;
        case 13:
        case 14:s
        case 15:
            i = [(r / unitConvers[10]).toFixed(2), "兆"];
            break;
        case 16:
            i = [(r / unitConvers[13]).toFixed(2), "千兆"];
            break;
        default:
            i = null
        }
    } else i = [e.toFixed(2), ""];
    return i
}

//尖峰平谷的值的单位换算：
function unitConver02(e, t, d) {
    if (null == e ) return "--";
    if ( 0 == e) return e;
    var i = null;
    if ((e = Number(e)) >= 1e3) {
        var r = parseInt(e);
        n = r.toString();
        o = n.length;
        if (void 0 == t) i = [n = e.toPrecision(o - 1).toString().match(/^\d.\d{2}/)[0], unitConversion[o - 1]];
        else switch (d) {//这里就以单位为标准，把数字进行转换  ，比如我已经定了前为单位  那么你输入1000就是0.1千
        case "千":
            i = (r / unitConvers[1]).toFixed(2);
            break;
      
        case "万":
            i = (r / unitConvers[2]).toFixed(2) ;
            break;
        case "千万":
            i = (r / unitConvers[5]).toFixed(2) ;
            break;
     
        case "亿":
            i = (r / unitConvers[6]).toFixed(2) ;
            break;
        case "千亿":
             i = (r / unitConvers[9]).toFixed(2);
            break;
      
        case "兆":
            i = (r / unitConvers[10]).toFixed(2);
            break;
        case "千兆":
            i = (r / unitConvers[13]).toFixed(2);
            break;
        default:
            i = null
        }
    } else i = e.toFixed(2);
    return i
}

//累计耗时时间相减：
function GetDateDiff(startTime, endTime, diffType){
	if(startTime==null || startTime==""){
			startTime=new Date();
		}
		if(endTime==null || endTime==""){
			endTime=new Date();
		}
		//将xxxx-xx-xx的时间格式，转换为 xxxx/xx/xx的格式
	    /*startTime = startTime.replace(/\-/g, "/");
	    endTime = endTime.replace(/\-/g, "/");*/
	    //将计算间隔类性字符转换为小写
	    diffType = diffType.toLowerCase();
	    var sTime =new Date(startTime); //开始时间
	    var eTime =new Date(endTime); //结束时间
	    //作为除数的数字
	    var timeType =1;
	    switch (diffType) {
	        case"second":
	            timeType =1000;
	        break;
	        case"minute":
	            timeType =1000*60;
	        break;
	        case"hour":
	            timeType =1000*3600;
	        break;
	        case"day":
	            timeType =1000*3600*24;
	        break;
	        default:
	        break;
	    }
	    return parseInt((eTime.getTime() - sTime.getTime()) / parseInt(timeType));
}
//报警级别的判断：
function levelSwitch(level){
				switch(level) {
								case 0:
								    level = '未知';
									return level;
								case 1:
									level = '一级';
									return level;
								case 2:
									level = '二级';
									return level;
								case 3:
									level = '三级';
									return level;
								case 4:
									level = '四级';
									return level;
								case 5:
									level = '五级';
									return level;
								case 6:
									level = '六级';
									return level;
								case 7:
									level = '七级';
									return level;
								case 8:
									level = '七级';
									return level;
								case 9:
									level = '七级';
									return level;
								default:
									level = '未知';
									return level;
							}
			}

//ajax请求数据过程中的加载效果：
/*$(function () {
    $.ajaxSetup({
        layerIndex:-1,
        beforeSend: function () {
            this.layerIndex = layer.load(0, { shade: [0.5, '#393D49'] });
        },
        complete: function () {
            layer.close(this.layerIndex);
        },
        error: function () {
            layer.alert('部分数据加载失败，可能会导致页面显示异常，请刷新后重试', {
                skin: 'layui-layer-molv'
               , closeBtn: 0
               , shift: 4 //动画类型
            });
        }
    });
});*/